package FulbitoFacil.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import FulbitoFacil.excepcion.DAOExcepcion;
import FulbitoFacil.negocio.*;

@WebServlet("/InsertarCanchaServlet")
public class InsertarCanchaServlet extends HttpServlet {
	static final long serialVersionUID = 1L;

	public InsertarCanchaServlet() {
		super();

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//System.out.println("123");
		int codLocal = Integer.parseInt(request.getParameter("local"));
		String nomCancha = request.getParameter("nomcancha");
		String caracteristicas = request.getParameter("caracte");
		String foto = request.getParameter("foto");
		PrintWriter out = response.getWriter();
		out.println(codLocal);
		out.println(nomCancha);
		out.println(caracteristicas);
		out.println(foto);
		GestionCancha NegCancha = new GestionCancha();

		HttpSession sesion = request.getSession();
		try {
			String ms = "";
			ms = NegCancha.insertarCancha(codLocal, nomCancha, caracteristicas,
					foto);

			response.sendRedirect(request.getContextPath()+ "/index.jsp");
			// response.sendRedirect(request.getContextPath() +
			// "/ListadoSala.jsp");
			// request.getSession().setAttribute("msg", ms);
			//request.getSession().setAttribute("ruta", "RegistrarCancha.jsp");
			// RequestDispatcher rd =
			// request.getRequestDispatcher("/mensaje.jsp");
			// rd.forward(request, response);
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
